package test1;

public class studentTest1 {
    public static void main(String[] args) {
        student[] arr = new student[3];

        student s1 = new student(1, "小明", 21);
        student s2 = new student(2, "小王", 19);
        student s3 = new student(3, "小赵", 25);

        arr[0] = s1;
        arr[1] = s2;
        arr[2] = s3;

        int index =getindex(arr,7);
        if (index>=0){
            arr[index]=null;
            printarr(arr);
        }else {
            System.out.println("当前id不存在，删除失败");
        }
    }


    public static int getindex(student[] arr, int id) {
        for (int i = 0; i < arr.length; i++) {
            student s = arr[i];
            if (s != null) {
                int sid = s.getId();
                if (sid == id) {
                    return i;
                }
            }
        }
        return -1;
    }

    public static void printarr(student[]arr) {
        for (int i = 0; i < arr.length; i++) {
            student s = arr[i];
            if (s!=null){
                System.out.println(s.getId()+","+s.getName());
            }
        }

    }

}
